package com.ilxqx.framework.amqp.repository;

import com.ilxqx.framework.amqp.entity.SysMessageLog;
import com.ilxqx.framework.system.repository.FrameworkRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 系统任务仓库接口
 * @author venus
 */
public interface SysMessageLogRepository extends FrameworkRepository<SysMessageLog, Long> {

    /**
     * 获取所有的重试消息
     * @param maxRetryCount 最大尝试次数
     * @param needRetryStatuses 需要尝试的消息状态
     * @return 消息List
     */
    @Query(value = "select * from sys_message_log o " +
            "where o.next_retry_time <= current_timestamp " +
            "and o.try_count < ?1 " +
            "and o.status in ?2", nativeQuery = true)
    List<SysMessageLog> getRetryList(Integer maxRetryCount, List<String> needRetryStatuses);

}
